<!--对账批次查询 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="账期年月日" prop="billDay">
        <el-date-picker
          v-model="queryParams.startBillDay"
          type="date"
          clearable
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="---" prop="checkDay">
        <el-date-picker
          v-model="queryParams.endBillDay"
          type="date"
          clearable
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="batchList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="账期年月日" align="center" prop="billDay" />
      <el-table-column label="对账年月日" align="center" prop="checkDay" />
      <el-table-column label="批次号" align="center" prop="batchNo" />
      <el-table-column label="渠道名称" align="center" prop="billType" >
        <template slot-scope="scope">
          拉卡拉
        </template>
      </el-table-column>
      <el-table-column label="平台支付订单笔数" align="center" prop="orderCount" />
      <el-table-column label="拉卡拉账单笔数" align="center" prop="checkCount" />
      <el-table-column label="差错账数量" align="center" prop="diffCount" />
      <el-table-column label="是否完成对账," align="center" prop="completeState" > <!--1:完成，2：未完成， 3：取消-->
        <template slot-scope="scope">
          <span v-if="scope.row.completeState==1">完成</span>
          <span v-if="scope.row.completeState==2">未完成</span>
          <span v-if="scope.row.completeState==3">取消</span>
        </template>
      </el-table-column>
      <el-table-column label="对账确认时间" align="center" prop="confirmDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.confirmDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生成方式" align="center" prop="createType" >
<!--        自动对账生成，2：手动对账生成）-->
        <template slot-scope="scope">
          <span v-if="scope.row.createType==1">自动</span>
          <span v-if="scope.row.createType==2">手动</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDelete(scope.row)"
            v-hasPermi="['batch:batch:remove']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBatch, getBatch, delBatch, addBatch, updateBatch } from "@/api/property/batch";
import {param} from "@/utils";

export default {
  name: "Batch",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 对账批次表格数据
      batchList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        billDay: "",
        checkDay: "",
        batchNum: null,
        batchNo: null,
        billType: null,
        orderCount: null,
        checkCount: null,
        diffCount: null,
        completeState: null,
        confirmDate: null,
        createType: null,
        downloadBatch: null,
        remarks: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        billDay: [
          { required: true, message: "账期年月日不能为空", trigger: "blur" }
        ],
        checkDay: [
          { required: true, message: "对账年月日(yyyymmdd)不能为空", trigger: "blur" }
        ],
        batchNum: [
          { required: true, message: "同一天内的批次序号(对账年月日内)不能为空", trigger: "blur" }
        ],
        batchNo: [
          { required: true, message: "批次号不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询对账批次列表 */
    getList() {
      this.loading = true;
      listBatch(this.queryParams).then(response => {
        this.batchList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        billDay: null,
        checkDay: null,
        batchNum: null,
        batchNo: null,
        billType: null,
        orderCount: null,
        checkCount: null,
        diffCount: null,
        completeState: null,
        confirmDate: null,
        createType: null,
        downloadBatch: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log(this.queryParams.billDay)

      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 查看按钮操作 */
    handleDelete(row) {
      const ids = row.batchNo;
     this.$router.push({name:"Detail",params:{"batchNo":ids}});

    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('batch/batch/export', {
        ...this.queryParams
      }, `batch_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
